package com.atguigu.tingshu.user.client;

import com.atguigu.tingshu.common.cache.GuiguCache;
import com.atguigu.tingshu.model.user.UserInfo;
import com.atguigu.tingshu.user.service.UserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * ClassName: UserClientController
 * Package: com.atguigu.tingshu.user.client
 * Description:用户信息的内部调用控制层
 */
@RestController
@RequestMapping("/client/user/userInfo")
public class UserClientController {
    @Autowired
    private UserInfoService userInfoService;

    /**
     * 根据用户id获取用户信息
     * @param userId
     * @return
     */
    @GuiguCache(prefix = "getUserInfo:")
    @GetMapping("/getUserInfo/{userId}")
    public UserInfo getUserInfo(@PathVariable("userId") Long userId) {
        return userInfoService.getById(userId);
    }

    /**
     * 查询用户是否购买专辑
     * @param userId
     * @param albumId
     * @return
     */
    @GetMapping("/isBuyAlbum/{userId}/{albumId}")
    public Boolean isBuyAlbum(@PathVariable(value = "userId") Long userId,@PathVariable(value = "albumId")Long albumId) {
        return userInfoService.isBuyAlbum(userId,albumId);
    }

    /**
     * 查询用户购买的声音id
     *
     * @param userId
     * @param albumId
     * @return
     */
    @GetMapping("/getBuyTrackList/{userId}/{albumId}")
    public Map<String, Integer> getBuyTrackList(@PathVariable(value = "userId") Long userId,
                                                @PathVariable(value = "albumId")Long albumId) {
        return userInfoService.getBuyTrackList(userId,albumId);
    }
}
